package com.example.jdai.jdai.ui;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.example.jdai.jdai.MyApplication;
import com.example.jdai.jdai.R;
import com.example.jdai.jdai.config.Config;
import com.example.jdai.jdai.rest.BackRest;

import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class YzmActivity extends Activity implements BackRest.DoLong{

    @BindView(R.id.tb)
    TopBar tb;
    @BindView(R.id.et_code)
    EditText etCode;
    @BindView(R.id.activity_yzm)
    LinearLayout activityYzm;
    int myplat=0;
    ProgressDialog pd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent=getIntent();
        final int plat=intent.getIntExtra("plat",0);
        myplat=plat;
        final String token=intent.getStringExtra("token");
        if(Config.ISDEBUG)
            Log.v("token",token);
        setContentView(R.layout.activity_yzm);
        pd = new ProgressDialog(this);
        pd.setMessage("请稍后...");
        pd.setCanceledOnTouchOutside(false);
        ButterKnife.bind(this);
        tb.setTopBarLisener(new TopBar.TopBarLisener() {
            @Override
            public void back() {
                finish();
            }

            @Override
            public void more() {
                pd.show();
                MyApplication.backRest.smsAllOk(etCode.getText().toString().trim(),plat,token,YzmActivity.this);
            }
        });
    }

    @Override
    public void doDone(int mark, Map str) {
        pd.dismiss();
        switch (mark){
            case 0:
                if(myplat==1){
                    startActivity(new Intent(YzmActivity.this,PhoneActivity.class));
                }
                finish();
                break;
            case 201:
                Toast.makeText(this,"验证码错误",Toast.LENGTH_SHORT).show();
        }
//        if(myplat==1){
//            startActivity(new Intent(YzmActivity.this,PhoneActivity.class));
//            finish();
//        }
//        else {
//            finish();
//        }

    }
}
